package com.tjsinfo.tjsoa.system.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;
import com.tjsinfo.tjsoa.system.bo.ISystemPrivateGroupBO;
import com.tjsinfo.tjsoa.system.vo.TSystemPrivategroup;

public class SystemPrivateGroupListAction extends Action{
	private ISystemPrivateGroupBO systemPrivateGroupBO;
	
	
	


	public ISystemPrivateGroupBO getSystemPrivateGroupBO() {
		return systemPrivateGroupBO;
	}





	public void setSystemPrivateGroupBO(ISystemPrivateGroupBO systemPrivateGroupBO) {
		this.systemPrivateGroupBO = systemPrivateGroupBO;
	}





	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		List<TSystemPrivategroup> list = null;
		Integer start = 0;
		JSONObject totalproperty = new JSONObject();
		if(request.getParameter("start") == null)
		{
			list = systemPrivateGroupBO.selectPrivateGroup(0, 15);
		}
		else
		{
			start = Integer.parseInt(request.getParameter("start"));
			list = systemPrivateGroupBO.selectPrivateGroup(start, 15);
		}
		totalproperty.put("totalProperty",systemPrivateGroupBO.selectTotalLine());
		
		
		JSONArray array = new JSONArray();
		for (TSystemPrivategroup systemPrivategroup : list) {
			JSONObject object = new JSONObject(systemPrivategroup);
			if (systemPrivategroup.getState() == 0) {
				object.put("start", "启用");
				
			} else {
				object.put("start", "禁用");
			}
			array.put(object);
		}
		totalproperty.put("root", array);
		response.getWriter().print(totalproperty);
		return null;
	}
}